package common.autoreview

class ImageDetectorChain: DetectorChain<String> {
    private val imageDetectors: MutableList<ImageDetector> = mutableListOf()
    private var key: String = ""
    private var index = 0
    private val defaultDetectResult = AutoReviewState.PASS

    init {
        imageDetectors.add(TerrorImageDetector())
        imageDetectors.add(NropImageDetector())
    }

    override fun detectOnChain(key: String): AutoReviewState {
        if (imageDetectors.isEmpty()){
           throw IllegalStateException("imageDetectors is Empty")
        }
        index = 0
        this.key = key
        return detectIn(index, this)
    }

    private fun detectIn(index: Int, chain: ImageDetectorChain): AutoReviewState {
         return imageDetectors[index].detect(key, chain)
    }

    override fun next(key: String): AutoReviewState {
        index++
        this.key = key
        //如果所有检测器都通过了
        if (index == imageDetectors.size){
            return defaultDetectResult
        }
        return detectIn(index, this)
    }
}